import { config, options } from '../js/config';
import { geoJSON } from '../js/getJSON';
import { createPolygonOrg, createCityPolygonLine, resetStyleOrg } from '../js/index';

let ImageLayer = '';
// 市经信驾驶舱地图
export function cockpitMapOrg() {
  // const { openLimit, limitX, limitY } = globalConfig;
  // 宁波市包含区县 面和边
  geoJSON('330200_full').then(res => {
    const { faceJSON } = res;
    const json = config.ALoca.GeoJSON(faceJSON);
    const Polygon = createPolygonOrg(json, options.data);
    config.map.on('click', function(e) {
      window.MAPCLICK();
      resetStyleOrg(Polygon);
    });
  });
  // 创建宁波市外描边
  geoJSON('330200').then(res => {
    const { LineJSON } = res;
    ImageLayer = createCityPolygonLine(config.ALoca.GeoJSON(LineJSON), 'org').ImageLayer;

    // if (openLimit) {
    //   setTimeout(() => {
    //     const bounds = config.map.getBounds();
    //     console.log(bounds);
    //     const northeast = bounds.northeast.toString().split(',');
    //     const southwest = bounds.southwest.toString().split(',');
    //     const limit1 = [[Number(northeast[0]) - limitX, Number(northeast[1]) - limitY], [Number(southwest[0]) + limitX, Number(southwest[1]) + limitY]];
    //     console.log(limit1, 'bounds');
    //     config.map.setLimitBounds(new AMap.Bounds(...limit1));
    //   }, 800);
    // }
  });
}

export function clearImageLayerOrg() {
  console.log(ImageLayer);
  ImageLayer && ImageLayer.setMap(null);
}
